package util;

import org.apache.mina.core.buffer.IoBuffer;

public class Convert {
	 public static String ioBufferToString(Object message)  
	    {  
	          if (!(message instanceof IoBuffer))  
	          {  
	            return "";  
	          }  
	          IoBuffer ioBuffer = (IoBuffer) message;  
	          byte[] b = new byte [ioBuffer.limit()];  
	          ioBuffer.get(b);  
	          StringBuffer stringBuffer = new StringBuffer();  
	      
	          for (int i = 0; i < b.length; i++)  
	          {  
	      
	           stringBuffer.append((char) b [i]);  
	          }  
	           return stringBuffer.toString();  
	    }  
	    
	    public static IoBuffer stringToIoBuffer(String str)  
	    {  
	      
	           byte bt[] = str.getBytes();  
	      
	           IoBuffer ioBuffer = IoBuffer.allocate(bt.length);  
	           ioBuffer.put(bt, 0, bt.length);  
	           ioBuffer.flip();  
	           return ioBuffer;  
	    }  
}
